<template>
  <div>
    <div class="header">
      <button><van-icon name="search" />&nbsp;搜索商品,共121077款好物</button>
    </div>
    <div class="main">
      <div class="left">
        <van-sidebar v-model="activeKey">
          <van-sidebar-item :title="item.name" key="12" v-for="item in sideBarList" :key="item.id" @click="sideBarHandler(item.id)" />
        </van-sidebar>
      </div>
      <div class="right">
        <van-pull-refresh v-model="tag" pulling-text=" " loosing-text=" " @refresh="onRefresh">
          <van-image :src="categoryBanner" alt="" width="7.04rem" height="2.56rem" class="banner" />
          <div v-for="item in categoryList" :key="item.id">
            <div class="title" v-if="item.name">{{ item.name }}</div>
            <div class="category">
              <div class="category-item" v-for="val in item.categoryList" :key="val.id">
                <van-image :src="val.wapBannerUrl" alt="" width="1.92rem" height="1.92rem" />
                <div class="item-title">{{ val.name }}</div>
              </div>
            </div>
          </div>
        </van-pull-refresh>
      </div>
    </div>
  </div>
</template>

<script>
import { reqCategorySidebar, reqCategoryList } from "@/api/category";
export default {
  name: "Category",
  data() {
    return {
      activeKey: 0,
      tag: false,
      sideBarList: [],
      categoryList: [],
      categoryBanner: "",
    };
  },
  methods: {
    onRefresh() {
      this.tag = false;
    },
    async sideBarHandler(id) {
      const result = await reqCategoryList(id);
      console.log(result);
      this.categoryList = result.data.categoryGroupList;
      this, (this.categoryBanner = result.data.currentCategory.bannerList[0].picUrl);
    },
  },
  async mounted() {
    const result = await reqCategorySidebar();
    this.sideBarList = result.data.categoryL1List;
    this.sideBarHandler(11);
  },
};
</script>

<style lang="less" scoped>
.header {
  z-index: 99;
  padding: 0 0.4rem;
  position: fixed;
  height: 1.1733rem;
  border-bottom: 0.0267rem solid #ccc;
  text-align: center;
  line-height: 1.5;
  background-color: #fff;
  button {
    font-size: 0.3733rem;
    width: 9.2rem;
    height: 0.7467rem;
    border: transparent;
    background-color: #ededed;
    color: #666;
    border-radius: 0.1333rem;
  }
}
.main {
  display: flex;
  padding-top: 1.1733rem;
  .left {
    position: fixed;
    width: 2.16rem;
    height: calc(100vh - 1.1733rem - 0.0267rem);
    border-right: 0.0267rem solid #ccc;
    .van-sidebar-item--select {
      color: #ab2b2b;
    }
    .van-sidebar-item--select::before {
      background-color: #ab2b2b;
      height: 100%;
    }
    :deep(.van-sidebar-item) {
      height: 0.6667rem;
      padding: 0;
      text-align: center;
      line-height: 0.6667rem;
      margin-top: 0.5333rem;
      background-color: #fff;
    }
  }
  .right {
    flex: 1;
    padding: 0.4rem 0.4rem 0.2667rem 0.4rem;
    margin-left: 2.1867rem;
    overflow: hidden;
    .banner {
      margin-bottom: 0.4267rem;
    }
    .title {
      height: 0.6933rem;
      margin-bottom: 0.32rem;
      padding-bottom: 0.1067rem;
      font-size: 0.3733rem;
      border-bottom: 0.0267rem solid #ccc;
      font-weight: bold;
      font-family: PingFangSC-Light;
    }
    .category {
      display: flex;
      flex-wrap: wrap;
      :nth-child(3n) {
        margin: 0 !important;
      }
      .category-item {
        margin-right: 0.4533rem;
        display: flex;
        flex-direction: column;
        width: 1.92rem;
        .item-title {
          font-size: 0.32rem;
          color: #333;
          text-align: center;
          height: 0.96rem;
        }
      }
    }
  }
}
</style>
